class IssueController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ issueInstanceList: Issue.list( params ) ]
    }

    def show = {
        def issueInstance = Issue.get( params.id )

        if(!issueInstance) {
            flash.message = "Issue not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ issueInstance : issueInstance ] }
    }

    def delete = {
        def issueInstance = Issue.get( params.id )
        if(issueInstance) {
            issueInstance.delete()
            flash.message = "Issue ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "Issue not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def issueInstance = Issue.get( params.id )

        if(!issueInstance) {
            flash.message = "Issue not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ issueInstance : issueInstance ]
        }
    }

    def update = {
        def issueInstance = Issue.get( params.id )
        if(issueInstance) {
            issueInstance.properties = params
            if(!issueInstance.hasErrors() && issueInstance.save()) {
                flash.message = "Issue ${params.id} updated"
                redirect(action:show,id:issueInstance.id)
            }
            else {
                render(view:'edit',model:[issueInstance:issueInstance])
            }
        }
        else {
            flash.message = "Issue not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def issueInstance = new Issue()
        issueInstance.properties = params
        return ['issueInstance':issueInstance]
    }

    def save = {
        def issueInstance = new Issue(params)
        if(!issueInstance.hasErrors() && issueInstance.save()) {
            flash.message = "Issue ${issueInstance.id} created"
            redirect(action:show,id:issueInstance.id)
        }
        else {
            render(view:'create',model:[issueInstance:issueInstance])
        }
    }
}
